<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;

class CreateTableController extends Controller
{
    //
    /**
     * 创建数据表
     *
     * @param $table_name
     * @return array
     */
    public function createTable($table_name)
    {
        try {
            if (\Schema::hasTable($table_name)){
                return $this->res_msg(1,'数据表已经存在');
            }
            // 创建数据表
            Schema::create($table_name, function (Blueprint $table){

                $table->increments('id');
                $table->timestamps();
                $table->engine = 'InnoDB';
            });

            return $this->res_msg(0,'数据表创建成功');

        } catch (\Exception $e){
            return $this->res_msg(2, '创建数据表异常');
        }
    }
}
